package cn.gok.service.impl;

import cn.gok.entity.Clazz;
import cn.gok.entity.Student;
import cn.gok.mapper.ClazzMapper;
import cn.gok.mapper.StudentMapper;
import cn.gok.service.ClazzService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {
    @Autowired
    ClazzMapper clazzMapper;
    @Autowired
    StudentMapper studentMapper;
    @Override
    public List<Clazz> selectStudentCidByClazz() {
        List<Clazz> list = clazzMapper.selectList(null);
        for (Clazz clazz : list) {
            QueryWrapper<Student> wrapper = new QueryWrapper<>();
            wrapper.eq("cid",clazz.getCid());
            List<Student> students = studentMapper.selectList(wrapper);
            clazz.setStudents(students);
        }
        return list;
    }
}
